package examples;

import com.hyperrealm.kiwi.text.*;

import java.io.*;

import com.hyperrealm.kiwi.io.*;

public class XMLParserTest
{

  public static void main(String args[])
  {
    try
    {
      FileInputStream fin = new FileInputStream("test.html");
      String html = StreamUtils.readStreamToString(fin);
      fin.close();

      HTMLParser parser = new HTMLParser(html);

      parser.parse();
    }
    catch(IOException ex)
    {
    }
    
  }

  static class HTMLParser extends XMLParser
  {

    HTMLParser(String text)
    {
      super(new StringReader(text), /*false*/ true);
    }

    protected void consumeElement(XMLElement e)
    {
      System.out.println("tag: " + e);
      System.out.println("Tag name: " + e.getTag());
    }

    protected void consumeText(String text)
    {
      text = text.replace((char)65533, ' ');
      
      System.out.println("Text: |" + text + "|");

    }

    protected void consumeEntity(String entity)
    {
      System.out.println("Entity: |" + entity + "|");
    }    
  }
}

